package com.yaxiya.fenlei.service;

import java.sql.SQLException;
import java.util.ArrayList;

import com.yaxiya.fenlei.entity.Fenlei;
import com.yaxiya.util.DBManager;
import com.yaxiya.util.QueryDataResult;

public class FenleiServiceImpl {

	public ArrayList<Fenlei> query(int page, int limit, String categoryid) {
		ArrayList<Fenlei> list = new ArrayList<Fenlei>();
		String sql = "select * from fenlei where categoryid="+categoryid;
		if (page != 0 && limit != 0) {
			sql += " limit " + (page - 1) * limit + "," + limit;
		}

		QueryDataResult qdr = DBManager.executeQuery(sql);
		if (qdr.rs != null) {
			try {
				while (qdr.rs.next()) {
					int id = qdr.rs.getInt("id");
					int categoryids = qdr.rs.getInt("categoryid");
					String biaoti = qdr.rs.getString("biaoti");
					String neirong = qdr.rs.getString("neirong");
					String shijian = qdr.rs.getString("shijian");
					Fenlei f = new Fenlei(id,categoryids, biaoti, neirong, shijian);
					list.add(f);
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
		qdr.close();
		return list;
	}

	public int count(String categoryid) {
		String sql = "select count(*) from fenlei where categoryid="+categoryid;
		QueryDataResult qdr = DBManager.executeQuery(sql);
		if (qdr.rs != null) {
			try {
				while (qdr.rs.next()) {
					int count = qdr.rs.getInt("count(*)");
					return count;
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}

		}
		qdr.close();
		return 0;
	}

}
